package com.thermofisher.dsc.amanda.security.handler;

import com.thermofisher.dsc.amanda.security.model.SecurityUserDetails;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.logout.LogoutSuccessHandler;
import org.springframework.stereotype.Component;

/**
 * Created by wenjie.yang on 1/3/2019.
 */
@Component
@Slf4j
public class MyLogoutSuccessHandler implements LogoutSuccessHandler {


  @Override
  public void onLogoutSuccess(HttpServletRequest httpServletRequest,
      HttpServletResponse httpServletResponse, Authentication authentication)
      throws IOException, ServletException {
    SecurityUserDetails user = (SecurityUserDetails) authentication.getPrincipal();
    log.info("USER : " + user.getUsername() + " LOGOUT SUCCESS !  ");
    httpServletResponse.sendRedirect("/logout");
  }
}
